#ifndef f_AudioStream_Resampler_h_
#define f_AudioStream_Resampler_h_

#include <windows.h>
#include <mmsystem.h>
#include <mmreg.h>
#include <msacm.h>

class CAudioResampler
{
public:
	CAudioResampler(WAVEFORMATEX *from, long samples, long new_rate, bool integral_conversion, bool hi_quality);
	virtual ~CAudioResampler();

	long Resample(BYTE *from, BYTE *to, long samples, long *lplBytes);
	long StreamLen() const { return stream_len; }
	
private:

	WAVEFORMATEX *m_from, *m_to;
	HACMSTREAM m_has;
//	typedef void (*AudioFormatConverter)(void *, void *, long);
	typedef long (*AudioPointSampler)(void *, void *, long, long, long);
	typedef long (*AudioUpSampler)(void *, void *, long, long, long);
	typedef long (*AudioDownSampler)(void *, void *, long *, int, long, long, long);

	
	AudioPointSampler ptsampleRout;
	AudioUpSampler upsampleRout;
	AudioDownSampler dnsampleRout;
	
//	void *m_src;
	long stream_len;

	BYTE *cbuffer;
	int bytesPerSample;
	long samp_frac;
	long accum;
	int holdover;
	long *filter_bank;
	int filter_width;
	bool fHighQuality;
	
	enum { BUFFER_SIZE=512 };

	long Upsample(BYTE *from, BYTE *to, long samples, long *lplBytes);
	long Downsample(BYTE *from, BYTE *to, long samples, long *lplBytes);

/*
public:
	AudioStreamResampler(AudioStream *source, long new_rate, bool integral_rate, bool high_quality);
	~AudioStreamResampler();

	long _Read(void *buffer, long max_samples, long *lplBytes);
	BOOL _isEnd();
	*/
};

#endif